<?php

include ('source/Connection.php');
$connection = new Connection(); //i created a new object
$connection->connectToDatabase(); // connected to the database
$connection->selectDatabase();// closed connection
$result = mysql_query("select s.url,s.click_count,s.id from path s where s.short_url like '%".$_GET['l']."'");

$row = mysql_fetch_row($result, MYSQL_NUM);
if(!empty($row)){
    $row[1] = $row[1]+1;
    $sql = mysql_query("update path p set p.click_count =".$row[1]." where p.id =".$row[2]);
    if (strpos($row[0], 'http') === 0) {
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=".$row[0]."\">";
    }else{
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://".$row[0]."\">";
    }

}else{
    header('location: index.html');
}
